<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Profile</title>
    <link href="/public/js/advanced-datatable/css/demo_page.css" rel="stylesheet" />
    <link href="/public/js/advanced-datatable/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="/public/js/data-tables/DT_bootstrap.css" />


    <link href="/public/js/iCheck/skins/flat/red.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/flat/green.css" rel="stylesheet">
    <?php $this->load->view('library/header');?>
</head>

<body class="sticky-header">

<section>
    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!-- page heading start-->
        <!--<div class="page-heading">-->
        <!--Page Tittle goes here-->
        <!--</div>-->
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
            <form id="handle_log" action="<?php echo base_url('purchase/log/po_id/'. $purchase_order['po_id']);?>" class="form-horizontal adminex-form" method="post" accept-charset="utf-8">
            <div class="row">
                <div class="col-md-12">
                    <div class="panel">
                        <header class="panel-heading">
                            采购批次信息
                            <span class="tools pull-right">
                                        <a class="fa fa-chevron-down" href="javascript:;"></a>
                                     </span>
                        </header>
                        <div class="panel-body">
                            <ul class="row p-info">
                                <li class="col-md-6">
                                    <div class="title">批次号：</div>
                                    <div class="desk"><?php echo $purchase_order['po_sn'];?></div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">供应商：</div>
                                    <div class="desk"><?php echo $purchase_order['suppliers_name'];?></div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">批次状态：</div>
                                    <div class="desk">
                                        <?php if ($purchase_order['po_status'] == 1) :?>
                                            等待采购
                                        <?php elseif ($purchase_order['po_status'] == 2) :?>
                                            采购中
                                        <?php elseif ($purchase_order['po_status'] == 3) :?>
                                            采购完成
                                        <?php endif;?>
                                    </div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">错误状态：</div>
                                    <div class="desk">
                                        <?php if ($purchase_order['is_wrong'] == 1) :?>
                                            异常批次
                                        <?php else:?>
                                            正常批次
                                        <?php endif;?>
                                    </div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">添加人：</div>
                                    <div class="desk">无</div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">添加时间：</div>
                                    <div class="desk"><?php echo $purchase_order['add_time'] ? date('Y-m-d H:i:s', $purchase_order['add_time']) : '无';?></div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">采购商品金额：</div>
                                    <div class="desk"><?php echo $purchase_order['goods_amount'];?></div>
                                </li>
                                <li class="col-md-6">
                                    <div class="title">阿里单号：</div>
                                    <div class="desk">
                                        <span class="ali-inv"><?php echo $purchase_order['ali_invoice_no'] ? $purchase_order['ali_invoice_no'] : 'N/A';?></span>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="panel">
                        <header class="panel-heading">
                            采购商品
                            <span class="tools pull-right">
                                <?php if ($purchase_order['po_status'] == 1) :?>
                                <button type="button" value="2" name="handle_type" data-toggle="modal" class="btn btn-info">设为采购中</button>
                                <?php endif;?>
                                <a class="fa fa-chevron-down" href="javascript:;"></a>
                            </span>
                        </header>
                        <div class="panel-body">
                            <section id="unseen">
                                <table class="table table-bordered table-striped table-condensed">
                                    <thead>
                                    <tr>
                                        <th width="10%">商品图片</th>
                                        <th >商品货号</th>
                                        <th class="numeric">SKU属性</th>
                                        <th class="numeric">采购数量</th>
                                        <th class="numeric">入库数量</th>
                                        <th class="numeric">采购金额</th>
                                        <th class="numeric">采购状态</th>
                                        <th width="15%" class="numeric">采购时间</th>
                                        <th width="13%" class="numeric">sku 操作</th>
                                        <th width="5%" class="numeric">产品操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($purchase_goods as $goods_id => $item) :?>
                                        <tr>
                                            <td class="center" rowspan="<?php echo count($item['sku']);?>"><img style="width: 80px;" src="<?php echo $item['original_img'];?>" /></td>
                                            <td  rowspan="<?php echo count($item['sku']);?>"><?php echo $item['goods_sn'];?></td>

                                        <?php $i = 1; foreach ($item['sku'] as $sk => $sku) : ?>
                                        <?php if ($i > 1):?>
                                            <tr >
                                        <?php endif;?>
                                            <td><?php echo $sku['sku_attr'];?></td>
                                            <td><?php echo $sku['pg_number'];?></td>
                                            <td><?php echo $sku['inv_number'];?></td>
                                            <td><?php echo $sku['purc_price'];?></td>
                                            <td>
                                                <?php if ($sku['pg_status'] == 1):?>
                                                    等待采购
                                                <?php elseif($sku['pg_status'] == 2) :?>
                                                    采购中
                                                <?php elseif($sku['pg_status'] == 3):?>
                                                    已采购
                                                <?php endif;?>
                                            </td>
                                            <td><?php echo date('Y-m-d H:i:s', $sku['add_time']);?></td>
                                            <td>
                                                <?php if ($sku['pg_status'] < 3) :?>
                                                <a class="btn btn-xs btn-info import-ajax" href="<?php echo base_url("purchase/quick_add_inventory_purchase/pg_id/{$sku['pg_id']}");?>">添加采购</a>
                                                <?php endif;?>
                                                <a class="btn btn-xs btn-info mymodal" data-id="<?php echo $sku['pg_id'];?>" data-toggle="modal" href="#myModal">查看销量</a>
                                            </td>
                                            <?php if ($i == 1): $i++;?>
                                                <td rowspan="<?php echo count($item['sku']);?>">
                                                    <?php if (!$item['status']) :?>
                                                        <button type="button" value="3" name="handle_type" data-goods-id="<?php echo $goods_id;?>" class="btn btn-xs btn-info">设为采购中</button>
                                                    <?php endif;?>
                                                    <a target="_blank" class="btn btn-xs btn-success" href="<?php echo $item['supp_url'];?>">采购链接</a>
                                                </td>
                                            <?php endif;?>
                                        </tr>
                                        <?php endforeach;?>
                                    <?php endforeach;?>
                                    </tbody>
                                </table>
                            </section>
                        </div>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="panel">
                        <textarea name="info" class="form-control input-lg p-text-area" rows="2" placeholder="输入备注信息..."></textarea>
                        <footer class="panel-footer">
                            <button type="button" name="handle_type" value="2" class="btn btn-post pull-right">批次拆分</button>
                            <button type="button" class="btn btn-post pull-right">导出采购商品</button>
                            <button type="button" name="handle_type" value="3" class="btn btn-post pull-right btn-ajax">设为已完成</button>
                            <button type="button" name="handle_type" value="1" class="btn btn-post pull-right">备注</button>
                            <ul class="nav nav-pills p-option"></ul>
                        </footer>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="panel">
                        <header class="panel-heading">
                            操作记录
                            <span class="tools pull-right">
                                        <a class="fa fa-chevron-down" href="javascript:;"></a>
                                     </span>
                        </header>
                        <div class="panel-body">
                            <?php if ($log_list) :?>
                                <table class="table  table-hover general-table">
                                    <thead>
                                    <tr>
                                        <th width="5%"> 操作员</th>
                                        <th width="5%" class="hidden-phone">采购状态</th>
                                        <th width="15%">备注信息</th>
                                        <th width="10%">添加时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($log_list as $row):?>
                                        <tr>
                                            <td><?php echo $row['admin_name'] ? $row['admin_name'] : '系统';?></td>
                                            <td class="hidden-phone"><?php echo $status['po_status'][$row['po_status']];?></td>
                                            <td><?php echo $row['po_info'];?></td>
                                            <td><?php echo date('Y-m-d H:i:s', $row['add_time']);?></td>
                                        </tr>
                                    <?php endforeach;?>
                                    </tbody>
                                </table>
                            <?php else:?>
                                <p>无消息</p>
                            <?php endif;?>
                        </div>
                    </div>
                </div>
            </div>
            </form>
        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer class="">
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal-2" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Form Tittle</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" role="form">
                    <div class="form-group">
                        <label class="sr-only" for="exampleInputEmail2">Email address</label>
                        <input type="email" class="form-control" id="exampleInputEmail5" placeholder="Enter email">
                    </div>
                    <button type="submit" class="btn btn-primary">Sign in</button>
                </form>
            </div>

        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">采购数据</h4>
            </div>

            <div class="modal-body row">

            </div>

        </div>
    </div>
</div>
<!-- modal -->

<?php $this->load->view('library/footer');?>

<script type="text/javascript">

    $('button[name="handle_type"]').click(function () {

        var t = setTimeout(function() {
            swal({
                imageUrl: '/public/images/Forrest.gif',
                title: '稍等...',
                allowOutsideClick: false,
                showConfirmButton: false
            });
        }, 200);

        var obj = $('#handle_log').serialize();
        var url = $('#handle_log').attr('action');
        obj += "&handle_type=" + $(this).val();
        obj += $(this).attr('data-goods-id') ? ('&goods_id='+$(this).attr('data-goods-id')) : '';

        $.post(url, obj, function(data){
            clearTimeout(t);
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });
        },'json');
        return false;
    });

    $('.a-ajax').click(function () {

        var url = $(this).attr('href');

        $.get(url, {is_ajax: 1}, function (data) {
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: data.stop ? data.stop : 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });

        }, 'json');

        return false;
    });

    $('.mymodal').click(function () {

        var id = $(this).attr('data-id');

        $.get('<?php echo base_url('purchase/ajax_sales');?>', {pg_id: id,is_ajax: 1}, function (data) {
            $('#myModal .modal-body').html(data);
        }, 'html');
    });

    $(".import-ajax").on("click", function () {

        var url = $(this).attr('href');

        $.get(url, function (data) {

            swal({
                title: '添加采购数量 - ',
                html: data,
                showCancelButton: true,
                confirmButtonText: 'Submit',
                showLoaderOnConfirm: true,
                preConfirm: function preConfirm() {
                    return $.post(url, {pg_number: $('#pg_number').val(), log_info: $('#log_info').val()}, function (data) {
                        return data;
                    },'json');
                },
                allowOutsideClick: false
            }).then(function (result) {
                console.log(result);
                if (result.value) {
                    var data = result.value;
                    swal({
                        type: data.status,
                        title: data.info
                    }).then(function(isConfirm) {
                        location.reload();
                    });
                }
            });

        },'html');

        return false;
    });


    $('.ali-inv').dblclick(function () {
        $(this).html('<input id="shipping-no" class="form-control no" style="padding: 4px; height: 28px; width: 180px; display: inline-block;" value="" /><button class="btn btn-info btn-xs btn-shipping-no" style="margin-top: 0; line-height: 23px;" type="button">确认</button>');
    });

    $("body").on("click", ".btn-shipping-no", function () {
        $.post("<?php echo base_url('purchase/ajax_add_ali_no'); ?>", { ali_invoice_no: $("#shipping-no").val(), po_id: '<?php echo $purchase_order['po_id'];?>'}, function(data){
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: data.stop ? data.stop : 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });
        },'json');
    });

    $('.no').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            $(".btn-shipping-no").click();
        }
    })
</script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

</body>
</html>
